<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="../templates/header_common::header_common(~{::title},~{::link})">
    <meta charset="UTF-8">
    <title>用户页面</title>
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/base.css}">
</head>
<body ng-app="shopping" ng-controller="userController">
<h1>用户</h1>
<button ng-click="queryById()">加载数据</button>
</body>
<script>
    var shopping = angular.module("shopping",[]);
    //定义服务层
    shopping.service("userService",function ($http) {
        this.loadUserById=function () {
            return $http.get("/user/1001");
        }
    });
    //定义控制器
    shopping.controller("userController",function ($scope,userService) {
        $scope.queryById=function () {
            userService.loadUserById().then(function success(response) {
                console.log(response);
            });
        }
    });
</script>
</html>